On the Relation between Context-Free Grammars and Parsing Expression Grammars
نویسندگان
چکیده
Context-Free Grammars (CFGs) and Parsing Expression Grammars (PEGs) have several similarities and a few differences in both their syntax and semantics, but they are usually presented through formalisms that hinder a proper comparison. In this paper we present a new formalism for CFGs that highlights the similarities and differences between them. The new formalism borrows from PEGs the use of parsing expressions and the recognition-based semantics. We show how one way of removing non-determinism from this formalism yields a formalism with the semantics of PEGs. We also prove, based on these new formalisms, how LL(1) grammars define the same language whether interpreted as CFGs or as PEGs, and also show how strong-LL(k), right-linear, and LLregular grammars have simple language-preserving translations from CFGs to PEGs. Once these classes of CFGs can be automatically translated to equivalent PEGs, we can reuse classic top-down grammars in PEG-based tools.
منابع مشابه
Generalized LR Parsing for Grammars with Contexts
The Generalized LR parsing algorithm for context-free grammars is notable for having a decent worst-case running time (cubic in the length of the input string), as well as much better performance on “good” grammars. This paper extends the Generalized LR algorithm to the case of “grammars with left contexts” (M. Barash, A. Okhotin, “An extension of context-free grammars with one-sided context sp...
متن کاملFrom LL-Regular to LL (1) Grammars: Transformations, Covers and Parsing
— In this paper it is shown that it is possible to transform any LL-regular grammar G into an LL{\) grammar G' in such a way that parsing G' is as good as parsing G. That ist a par se of a sentence of grammar G can be obtained with a simple string homomorphism from the parse of a corresponding sentence of G'. Since any LL (k) grammar is an LL-regular grammar the results which are obtained are v...
متن کاملA New Method for Dependent Parsing
Dependent grammars extend context-free grammars by allowing semantic values to be bound to variables and used to constrain parsing. Dependent grammars can cleanly specify common features that cannot be handled by context-free grammars, such as length fields in data formats and significant indentation in programming languages. Few parser generators support dependent parsing, however. To address ...
متن کاملSimple, Functional, Sound and Complete Parsing for All Context-Free Grammars
Parsers for context-free grammars can be implemented directly and naturally in a functional style known as “combinator parsing”, using recursion following the structure of the grammar rules. However, naive implementations fail to terminate on left-recursive grammars, and despite extensive research the only complete parsers for general contextfree grammars are constructed using other techniques ...
متن کاملA preliminary report on generalized LR parsing for Boolean grammars
The generalized LR parsing algorithm for context-free grammars, invented by Tomita in 1986, is extended for the case of Boolean grammars – a recently introduced generalization of context-free grammars with logical connectives added to the formalism of rules. A high-level description of the algorithm, an elaborate example of its operation and a suggested implementation are provided. The algorith...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید
ثبت ناماگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید
ورودعنوان ژورنال:
- Sci. Comput. Program.
دوره 89 شماره
صفحات -
تاریخ انتشار 2014